package com.linkgie.galaxyframework.crypto.context;

import java.io.OutputStream;

import com.linkgie.galaxyframework.crypto.AsymmetricCipherService;
import com.linkgie.galaxyframework.crypto.PrivateKey;
import com.linkgie.galaxyframework.crypto.PublicKey;
import com.linkgie.galaxyframework.crypto.Signature;
import com.linkgie.galaxyframework.crypto.SignatureService;
import com.linkgie.galaxyframework.crypto.Signer;
import com.linkgie.galaxyframework.crypto.Verifier;
import com.linkgie.galaxyframework.crypto.spi.AsymmetricCipherFuncSPI;
import com.linkgie.galaxyframework.crypto.spi.AsymmetricFuncSPI;
import com.linkgie.galaxyframework.crypto.spi.SignatureFuncSPI;

/**
 * 同时支持签名和加密的非对称密码算法的实现；
 * 
 * @author Hike
 *
 */
public class AsymmetricCipherSignatureServiceImpl extends AsymmetricServiceBase<AsymmetricFuncSPI>
		implements AsymmetricCipherService, SignatureService {

	private final SignatureService signatureService;

	private final AsymmetricCipherService cipherService;

	public AsymmetricCipherSignatureServiceImpl(AsymmetricFuncSPI innerService) {
		super(innerService);
		this.signatureService = new SignatureServiceImpl((SignatureFuncSPI) innerService);
		this.cipherService = new AsymmetricCipherServiceImpl((AsymmetricCipherFuncSPI) innerService);
	}

	@Override
	public byte[] encrypt(PublicKey key, byte[] plainBytes) {
		return cipherService.encrypt(key, plainBytes);
	}

	@Override
	public byte[] encrypt(PublicKey key, byte[] plainBytes, int offset, int length) {
		return cipherService.encrypt(key, plainBytes, offset, length);
	}

	@Override
	public int encrypt(PublicKey key, byte[] plainBytes, int offset, int length, OutputStream out) {
		return cipherService.encrypt(key, plainBytes, offset, length, out);
	}

	@Override
	public byte[] encrypt(byte[] rawKey, byte[] plainBytes) {
		return cipherService.encrypt(rawKey, plainBytes);
	}

	@Override
	public byte[] encrypt(byte[] rawKey, byte[] plainBytes, int offset, int length) {
		return cipherService.encrypt(rawKey, plainBytes, offset, length);
	}

	@Override
	public int encrypt(byte[] rawKey, byte[] plainBytes, int offset, int length, OutputStream out) {
		return cipherService.encrypt(rawKey, plainBytes, offset, length, out);
	}

	@Override
	public byte[] decrypt(PrivateKey key, byte[] cipherBytes) {
		return cipherService.decrypt(key, cipherBytes);
	}

	@Override
	public byte[] decrypt(PrivateKey key, byte[] cipherBytes, int offset, int length) {
		return cipherService.decrypt(key, cipherBytes, offset, length);
	}

	@Override
	public int decrypt(PrivateKey key, byte[] cipherBytes, int offset, int length, OutputStream out) {
		return cipherService.decrypt(key, cipherBytes, offset, length, out);
	}

	@Override
	public byte[] decrypt(byte[] rawKey, byte[] cipherBytes) {
		return cipherService.decrypt(rawKey, cipherBytes);
	}

	@Override
	public byte[] decrypt(byte[] rawKey, byte[] cipherBytes, int offset, int length) {
		return cipherService.decrypt(rawKey, cipherBytes, offset, length);
	}

	@Override
	public int decrypt(byte[] rawKey, byte[] cipherBytes, int offset, int length, OutputStream out) {
		return cipherService.decrypt(rawKey, cipherBytes, offset, length, out);
	}

	@Override
	public Signature sign(PrivateKey privKey, byte[] data) {
		return signatureService.sign(privKey, data);
	}

	@Override
	public Signature sign(PrivateKey privKey, byte[] data, int offset, int length) {
		return signatureService.sign(privKey, data, offset, length);
	}

	@Override
	public byte[] sign(byte[] rawPrivKey, byte[] data) {
		return signatureService.sign(rawPrivKey, data);
	}

	@Override
	public byte[] sign(byte[] rawPrivKey, byte[] data, int offset, int length) {
		return signatureService.sign(rawPrivKey, data, offset, length);
	}

	@Override
	public boolean verify(Signature signature, PublicKey pubKey, byte[] data) {
		return signatureService.verify(signature, pubKey, data);
	}

	@Override
	public boolean verify(Signature signature, PublicKey pubKey, byte[] data, int offset, int length) {
		return signatureService.verify(signature, pubKey, data, offset, length);
	}

	@Override
	public boolean verify(byte[] rawSignature, byte[] rawPubKey, byte[] data) {
		return signatureService.verify(rawSignature, rawPubKey, data);
	}

	@Override
	public boolean verify(byte[] rawSignature, byte[] rawPubKey, byte[] data, int offset, int length) {
		return signatureService.verify(rawSignature, rawPubKey, data, offset, length);
	}

	@Override
	public Signer createSigner(PrivateKey privKey) {
		return signatureService.createSigner(privKey);
	}

	@Override
	public Verifier createVerifier(Signature signature, PublicKey pubKey) {
		return signatureService.createVerifier(signature, pubKey);
	}

}
